package com.tcd.service.impl;

import com.tcd.mapper.ClaimsDetailMapper;
import com.tcd.pojo.Claims;
import com.tcd.mapper.ClaimsMapper;
import com.tcd.pojo.ClaimsDetail;
import com.tcd.service.ClaimsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 理算表 服务实现类
 * </p>
 *
 * @author space
 * @since 2021-05-27
 */
@Service
public class ClaimsServiceImpl extends ServiceImpl<ClaimsMapper, Claims> implements ClaimsService {
    @Autowired(required = false)
    ClaimsMapper claimsMapper;
    @Autowired(required = false)
    ClaimsDetailMapper claimsDetailMapper;

    @Override
    public Claims getClaimsById(Integer claimsId) {
        return claimsMapper.selectClaimsById(claimsId);
    }

    @Override
    public List<Claims> getClaims(Integer pageIndex, Integer pageSize, Integer claimsNumber, Integer warrantyId, String claimsType, String state) {
        return claimsMapper.selectClaims(pageIndex, pageSize, claimsNumber, warrantyId, claimsType, state);
    }

    @Override
    public Integer getClaimsCount(Integer claimsNumber, Integer warrantyId, String claimsType, String state) {
        return claimsMapper.selectClaimsCount(claimsNumber, warrantyId, claimsType, state);
    }

    @Override
    public Integer addClaims(Claims claims) {
        claims.setClaimsNumber("");
        int row = claimsMapper.insert(claims);
        System.out.println(claims.getClaimsId());
        if (row > 0 && claims.getDetails() != null){
            for (ClaimsDetail detail : claims.getDetails()) {
                detail.setClaimsId(claims.getClaimsId());
                row += claimsDetailMapper.insert(detail);
            }
        }
        return row;
    }

    @Override
    public Integer updateClaims(Claims claims){
        return claimsMapper.updateById(claims);
    }




}
